# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Llewelyn Trahaearn <WoefulDerelict at GMail dot com>
# Contributor: rtfreedman  <rob dot til dot freedman at gmail dot com>
# Contributor: Limao Luo <luolimao+AUR at gmail dot com>
# Contributor: SpepS <dreamspepser at yahoo dot it>

pkgbase=rtaudio
pkgname=(
  rtaudio
  rtaudio-docs
)
pkgver=5.2.0
pkgrel=2
pkgdesc="A set of C++ classes that provide a common API for realtime audio input/output."
arch=(loong64 x86_64)
url="https://www.music.mcgill.ca/~gary/rtaudio/"
license=('custom:RtAudio')
makedepends=(
  alsa-lib
  doxygen
  gcc-libs
  glibc
  jack
  meson
  libpulse
)
source=(https://github.com/thestk/$pkgname/archive/$pkgver/$pkgname-$pkgver.tar.gz)
sha512sums=('34e78522778db13d95d4465d7c6a808a63b34d4e1bd0b88113b6390f7b192017e405d0d9ac8fbb1151129627688626d17569dc47da420f7b4631892eb1adff11')
b2sums=('1949885c3cbb2846e083fd25ec06ed5ca716563dd4c121f6985e2487488d88b9ffb62078185fe2f4261083c8c1ed4c3e8502d25614767d70d2ab316d77f51eeb')

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

build() {
  local meson_options=(
    -D core=disabled
    -D dsound=disabled
    -D asio=disabled
    -D wasapi=disabled
    -D docs=true
    -D install_docs=true
  )

  arch-meson $pkgbase-$pkgver build "${meson_options[@]}"
  meson compile -C build
}

check() {
  meson test -C build --print-errorlogs
}

package_rtaudio() {
  depends=(
    gcc-libs
    glibc
    alsa-lib
    jack
    libpulse
  )
  optdepends=('rtaudio-docs: for documentation')
  provides=(librtaudio.so)

  meson install -C build --destdir "$pkgdir"
  install -vDm 644 $pkgbase-$pkgver/LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"

  _pick $pkgbase-docs "$pkgdir/usr/share/doc"
}

package_rtaudio-docs() {
  pkgdesc+=" - documentation"

  mv -v $pkgname/* "$pkgdir"

  install -vDm 644 $pkgbase-$pkgver/{README.md,ChangeLog,doc/release.txt} -t "$pkgdir/usr/share/doc/$pkgbase/"
  install -vDm 644 $pkgbase-$pkgver/LICENSE -t "$pkgdir/usr/share/licenses/$pkgname"
}
